#include <sstream>
#include <queue>
#include <iostream>
using namespace std;


struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};


class Solution {
public:
    // 中序遍历
    void inorder(TreeNode* root, vector<int>& nums){
        if(root == nullptr) return;
        inorder(root->left, nums);
        nums.push_back(root->val);
        inorder(root->right, nums);
    }

    pair<int, int> findTwoNeedSwap(vector<int>& nums){
        int sz = nums.size();
        int index1 = -1, index2 = -1;
        for(int i = 0; i < sz - 1; i++){
            if(nums[i+1] < nums[i]){
                if(index1 == -1){
                    index1 = i;
                }
                index2 = i + 1;
            }
        }
        return {nums[index1], nums[index2]};
    }

    //先序遍历二叉树，交换节点
    // count 的作用是记录更新节点的数量，初始化2，减到0 退出，可提前结束递归，提高时间性能
    void recover(TreeNode* root, int count, int val1, int val2){
        if(root == nullptr) return;
        if(val1 == root->val || val2 == root->val){
            root->val = val1 == root->val ? val2 : val1;
            if(--count == 0){
                return;
            }
        }
        recover(root->left, count, val1, val2);
        recover(root->right, count, val1, val2);

    }

    void recover2(TreeNode* root, int val1, int val2){
        if(nullptr == root) return;
        if(val1 == root->val || val2 == root->val){
            root->val = val1 == root->val ? val2 : val1;
        }
        recover2(root->left, val1, val2);
        recover2(root->right, val1, val2);
    }

    void recoverTree(TreeNode* root) {
        // nums 保存中序遍历序列
        vector<int> nums;
        inorder(root, nums);
        pair<int, int> ret = findTwoNeedSwap(nums);
        // recover(root, 2, ret.first, ret.second);
        recover2(root, ret.first, ret.second);
    }

};

void trimLeftTrailingSpaces(string &input) {
    input.erase(input.begin(), find_if(input.begin(), input.end(), [](int ch) {
        return !isspace(ch);
    }));
}

void trimRightTrailingSpaces(string &input) {
    input.erase(find_if(input.rbegin(), input.rend(), [](int ch) {
        return !isspace(ch);
    }).base(), input.end());
}

TreeNode* stringToTreeNode(string input) {
    trimLeftTrailingSpaces(input);
    trimRightTrailingSpaces(input);
    input = input.substr(1, input.length() - 2);
    if (!input.size()) {
        return nullptr;
    }

    string item;
    stringstream ss;
    ss.str(input);

    getline(ss, item, ',');
    TreeNode* root = new TreeNode(stoi(item));
    queue<TreeNode*> nodeQueue;
    nodeQueue.push(root);

    while (true) {
        TreeNode* node = nodeQueue.front();
        nodeQueue.pop();

        if (!getline(ss, item, ',')) {
            break;
        }

        trimLeftTrailingSpaces(item);
        if (item != "null") {
            int leftNumber = stoi(item);
            node->left = new TreeNode(leftNumber);
            nodeQueue.push(node->left);
        }

        if (!getline(ss, item, ',')) {
            break;
        }

        trimLeftTrailingSpaces(item);
        if (item != "null") {
            int rightNumber = stoi(item);
            node->right = new TreeNode(rightNumber);
            nodeQueue.push(node->right);
        }
    }
    return root;
}

int stringToInteger(string input) {
    return stoi(input);
}

string treeNodeToString(TreeNode* root) {
    if (root == nullptr) {
      return "[]";
    }

    string output = "";
    queue<TreeNode*> q;
    q.push(root);
    while(!q.empty()) {
        TreeNode* node = q.front();
        q.pop();

        if (node == nullptr) {
          output += "null, ";
          continue;
        }

        output += to_string(node->val) + ", ";
        q.push(node->left);
        q.push(node->right);
    }
    return "[" + output.substr(0, output.length() - 2) + "]";
}

int main() {
    string line;
    while (getline(cin, line)) {
        TreeNode* root = stringToTreeNode(line);
        Solution slu;
        slu.recoverTree(root);

        string out = treeNodeToString(root);
        cout << out << endl;
    }
    return 0;
}